unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Image1: TImage;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
const
  Size = 10000;
var
  Form1: TForm1;
  ArrForBubble, ArrForShaker, ArrForAdvBubble, ArrForHeap, ArrForGnomer : array [0..Size] of Integer;
  MainArray : Array [0..Size] of Integer;
  BubbleT , ShakerT, AdvBubbleT, HeapT, GnomeT : Integer;
implementation

{$R *.dfm}
function Max(a, b, c, d , e: Integer)  : Integer;
Begin
  if((a >= b) and (a >= c) and (a >= d) and(a >= e)) then
    Max := a;
  if((b >= a) and (b >= c) and (b >= d) and (b >= e)) then
    Max := b;
  if((c >= a) and (c >= b) and (c >= d) and (c >= e)) then
    Max := c;
  if((d >= a) and (d >= b) and (d >= c)and (d >= e)) then
    Max := d;
  if((e >= a) and (e >= b) and (e >= c) and (e >= d))  then
    Max := e;
End;


procedure CreateArray();
var
  I : Integer;
Begin
  For I := 0 to Size do
      MainArray[I] := Random(100);
End;

procedure Bubble();
var
  tmp, I, J : Integer;

Begin
  For I := 0 to Size do
    ArrForBubble[I] := MainArray[I];
  For I := 0 to Size  do
    For J := 0 to Size - I do
      If(ArrForBubble[J] > ArrForBubble[J + 1]) then
        Begin
          tmp := ArrForBubble[J];
          ArrForBubble[J] := ArrForBubble[J + 1];
          ArrForBubble[J + 1] := tmp;
        End;
End;

procedure Shaker();
var
  I, J : Integer;
  tmp : Integer;
Begin
  For I := 0 to Size do
    ArrForShaker[I] := MainArray[I];
  For I := 0 to Size do
  Begin
    if ((I mod 2) = 0) then
      Begin
        For J := I div 2  to (Size - (I div 2)) do
          If(ArrForShaker[J] > ArrForShaker[J + 1]) then
            Begin
              tmp := ArrForShaker[J];
              ArrForShaker[J] := ArrForShaker[J + 1];
              ArrForShaker[J + 1] := tmp;
            End;
      End
    else
      Begin
        For J := Size - (I div 2) downto I div 2 do
          Begin
            if(ArrForShaker[J] > ArrForShaker[J - 1]) then
              Begin
                tmp := ArrForShaker[J];
                ArrForShaker[J] := ArrForShaker[J - 1];
                ArrForShaker[J - 1] := tmp;
              End;
          End;
      End;
  End;

End;

procedure AdvBubble();
var
  I, J , Flag, Tmp  : Integer;
Begin
 For I := 0 to Size do
    ArrForBubble[I] := MainArray[I];
  For I := 0 to Size  do
  Begin
    Flag := 0;
    For J := 0 to Size - I do
    Begin
      If(ArrForBubble[J] > ArrForBubble[J + 1]) then
        Begin
          Flag := 1;
          tmp := ArrForBubble[J];
          ArrForBubble[J] := ArrForBubble[J + 1];
          ArrForBubble[J + 1] := tmp;
        End;
    End;
    if(Flag = 0) then
      Break;
  End;
End;

procedure Heap();
Begin
End;

procedure Gnome();
Begin
End;

procedure Draw();
Begin
  Form1.Image1.Canvas.Rectangle(0, 0, 1000, 1000);
  Form1.Image1.Canvas.Rectangle(0, 0,   Round(300 * BubbleT /max(BubbleT, ShakerT,AdvBubbleT, HeapT, GnomeT)), 10);
  Form1.Image1.Canvas.Rectangle(0, 10,  Round(300 * ShakerT / max(BubbleT, ShakerT,AdvBubbleT, HeapT, GnomeT)), 20);
  Form1.Image1.Canvas.Rectangle(0, 20,  Round(300 * AdvBubbleT / max(BubbleT, ShakerT,AdvBubbleT, HeapT, GnomeT)), 30);
  Form1.Image1.Canvas.Rectangle(0, 30 , Round(300 * HeapT / max(BubbleT, ShakerT,AdvBubbleT, HeapT, GnomeT)),40);
  Form1.Image1.Canvas.Rectangle(0, 40,  Round(300 * GnomeT / Max(BubbleT, ShakerT,AdvBubbleT, HeapT, GnomeT)), 50);
End;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  t :  Integer;
begin
  CreateArray();
  t := GetTickCount();
  Bubble();
  BubbleT := BubbleT + GetTickCount() - t;
  t := GetTickCount();
  Shaker();
  ShakerT := ShakerT + Gettickcount() - t;
  t := GetTickCount();
  AdvBubble();
  AdvBubbleT := AdvBubbleT + GettickCount() - t;
  t := GetTickCount();
  Heap();
  HeapT := HeapT  + GetTickCount() - t;
  t := GetTickCount();
  Gnome();
  GnomeT := GnomeT + GetTickCount() - t;
  Draw();
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  BubbleT :=0;
  ShakerT := 0;
  AdvBubbleT := 0;
  HeapT := 0;
  GnomeT := 0;
end;

end.




